<?php session_start(); include 'db_connection.php'; ?>
<?php 
    $sql = 'SELECT * FROM donation_projects ORDER BY id DESC LIMIT 4';
    $result = mysqli_query($conn, $sql);
    $list = [];
    if ($result) {
        while($row = $result->fetch_assoc()) {
            $list[] = $row;
        }
    }

    $sql = 'SELECT * FROM volunteers ORDER BY id DESC LIMIT 4';
    $result = mysqli_query($conn, $sql);
    $nlist = [];
    if ($result) {
        while($row = $result->fetch_assoc()) {
            $nlist[] = $row;
        }
    }
    mysqli_close($conn);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>贫困儿童关爱网站</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<? require 'common/nav.php'; ?>
<main>
    <section class="project">
        <h2>最新捐助项目</h2>
        <!-- 捐助项目列表 -->
        <ul>
            <?php foreach($list as $item) { ?>
            <li>
                <h3><?php echo $item['project_name']; ?></h3>
                <p><?php echo $item['description']; ?></p>
                <p>开始结束时间:<?php echo $item['start_date'] . '/' . $item['end_date']; ?></p>
                <p>目标金额:<?php echo $item['target_amount']; ?>, 已筹金额:<?php echo $item['collected_amount']; ?></p>
            </li>
            <?php } ?>
        </ul>
    </section>
    <section>
        <h2>新闻更新</h2>
         <ul class="news">
            <?php foreach ($nlist as $row) { ?>
            <li>志愿者: <?php echo $row['name']; ?> ,在<?php echo substr($row['signup_time'], 0, 16)  ; ?>申请报名</li>
            <?php } ?>
         </ul>
    </section>
</main>
<footer>
    <p>联系我们: contact@example.com</p>
</footer>
</body>
</html>